package educationaladministrationsystem.CSM.Controller.Root;

import educationaladministrationsystem.Class.MajorProgram;
import educationaladministrationsystem.Result.Result;
import educationaladministrationsystem.CSM.Mapper.Service.Root.RootProfessionalManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Root/ProfessionMajor")
public class RootProfessionMajorController {
    @Autowired
    private RootProfessionalManagementService rootProfessionalManagementService;

    @GetMapping("/getAllFacultiesInformation")
    public Result getAllFacultiesInformation() {
        return Result.success(rootProfessionalManagementService.getAllFacultiesInformation());
    }

    @GetMapping("/getFacultiesName")
    public Result getFacultiesName(@RequestParam String id) {
        return Result.success(rootProfessionalManagementService.getFacultiesName(id));
    }

    @GetMapping("/getAllProfessionMajor")
    public Result getAllProfessionMajor(@RequestParam int page, @RequestParam int pageNumber) {
        return Result.success(rootProfessionalManagementService.getAllProfessionMajor(page, pageNumber));
    }

    @PostMapping("/addNewProfessionMajor")
    public Result addNewProfessionMajor(@RequestBody MajorProgram majorProgram) {
        rootProfessionalManagementService.addNewProfessionMajor(majorProgram);
        return Result.success();
    }

    @GetMapping("/getAllPage")
    public Result getPage(@RequestParam int pageNumber) {
        return Result.success(rootProfessionalManagementService.getAllPage(pageNumber));
    }

    @GetMapping("/updateProfessionMajorInformation")
    public Result getUpdateProfessionMajorInformation(@RequestParam int id) {
        return Result.success(rootProfessionalManagementService.getUpdateProfessionMajorInformation(id));
    }

    @PostMapping("/updateProfessionMajor")
    public Result updateProfessionMajor(@RequestBody MajorProgram majorProgram, @RequestParam String oldId) {
        rootProfessionalManagementService.updateProfessionMajor(majorProgram.getId(), majorProgram.getName(), majorProgram.getFacultiesId(), oldId);
        return Result.success();
    }

    @PostMapping("/deleteProfessionMajor")
    public Result deleteProfessionMajor(@RequestParam String id) {
        rootProfessionalManagementService.deleteProfessionMajor(id);
        return Result.success();
    }
}
